package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "品牌接口")
@RestController
@RequestMapping("/admin/product")
public class BaseTrademarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;

    //http://api.gmall.com/admin/product/baseTrademark/{page}/{limit}
    @ApiOperation("获取品牌分页列表")
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result getTrademark(@PathVariable("page") Long page,@PathVariable("limit") Long limit){
        //封装分页参数
        Page<BaseTrademark> page1 = new Page<>(page,limit);
        //查询的 分页结果
        Page<BaseTrademark> result = baseTrademarkService.page(page1);
        return Result.ok(result);
    }

    //http://api.gmall.com/admin/product/baseTrademark/save
    @ApiOperation("添加品牌")
    @PostMapping("/baseTrademark/save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    //http://api.gmall.com/admin/product/baseTrademark/remove/{id}
    @ApiOperation("删除品牌")
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result delete(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    //http://api.gmall.com/admin/product/baseTrademark/get/13
    @ApiOperation("根据Id获取品牌")
    @GetMapping("/baseTrademark/get/{id}")
    public Result get(@PathVariable("id") Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    //http://api.gmall.com/admin/product/baseTrademark/update
    @ApiOperation("修改品牌")
    @PutMapping("/baseTrademark/update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }
}
